package com.lottery.material.controller.portal.bank;

import com.lottery.material.controller.base.BaseController;
import com.lottery.material.enumeration.ResultEnum;
import com.lottery.material.jedis.JedisClient;
import com.lottery.material.resolver.CustomException;
import com.lottery.material.service.portal.config.BankDictService;
import com.lottery.material.service.portal.user.PortalUserInfoService;
import com.lottery.material.util.ParameterUtil;
import com.lottery.material.util.ResponseResult;
import com.lottery.material.vo.portal.config.BankDictVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "开户银行列表接口", tags = { "开户银行列表接口" })
@Controller
@RequestMapping("/portal/bank")
@Slf4j
public class BandInfoController extends BaseController {

    @Autowired
    BankDictService bankDictService;

    @ApiOperation(value="开户银行列表接口", notes="开户银行列表接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = false, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = false, dataType = "String"),
    })
    @RequestMapping(value = "/getBankList",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult getBankList(HttpServletRequest request){
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        Map<String, Object> resultMap = new HashMap<>();
        List<BankDictVo> bankHotList = new ArrayList<>();
        List<BankDictVo> bankAllList = bankDictService.findBankDictList();
        for (BankDictVo bankDictVo : bankAllList){
            if(bankDictVo.getIsHot() == 2){
                bankHotList.add(bankDictVo);
            }
        }
        resultMap.put("bankHot", bankHotList);
        resultMap.put("bankAll", bankAllList);
        return ResponseResult.buildSuccess(resultMap);
    }
}

